.class public BinomialCalculator

.method public static calRawI(I)I
.limit locals 4
.limit stack 3
	iconst_1
	istore_1	;a=1
	bipush -2
	istore_2	;b=-2
	bipush -35
	istore_3 	;c=-35

	iload_0 
	iload_0
	imul		;x^2 on top of stack
	iload_1
	imul		;ax^2 on top of stack
	iload_0
	iload_2		;b on top of stack, then x, then ax^2
	imul		;bx on top of stack, then ax^2
	iadd
	iload_3		;c on top of stack, then (bx + ax^2)
	iadd		; (c + bx + ax^2) on top of stack
	
	ireturn                                  
.end method                                    

.method public static calRawD(D)D
.limit locals 8
.limit stack 6
	ldc2_w 1D
	dstore_2	;a=1.0
	ldc2_w -2.0D                       
	dstore 4	;b=-2.0                      
	ldc2_w -35.0D
	dstore 6 	;c=-35.0
	
	dload_0 
	dload_0
	dmul		;x^2 on top of stack
	dload_2
	dmul		;ax^2 on top of stack
	dload_0
	dload 4		;b on top of stack, then x, then ax^2
	dmul		;bx on top of stack, then ax^2
	dadd
	dload 6		;c on top of stack, then (bx + ax^2)
	dadd		; (c + bx + ax^2) on top of stack                                     
	                                          
	dreturn                                   
.end method

; The refined cal method has advantage over the raw one, where using of
; imul reduced
.method public static calRefineI(I)I
	iconst_1
	istore_1	;a=1
	bipush -2
	istore_2	;b=-2
	bipush -35
	istore_3 	;c=-35
	
	iload_0
	iload_1
	imul		;ax on top
	iload_2		;b on top, then ax
	iadd		; (b + ax) on top
	iload_0		;x on top, then (b + ax)
	imul		; (b + ax)x on top
	iload_3		;c on top, then (b + ax)x
	iadd		;((ax + b)x) + c on top
	
	ireturn
.end method

.end class
